﻿using System;
using QLNet;
using p = FinPlusAnalytics.QLConvParser;
using u = FinPlusUtility.Utility;

namespace FinPlusAnalytics
{
    public class VanillaSwapTrade : Trade
    {
        public string Id { get; private set; }

        //construct
        public VanillaSwapTrade(string marketName, string cacheName, string id, string curveName, double nominal, DateTime start,
            DateTime maturity, double fixedRate, string payRec, string index, double spread, string fixLegFrq, string fltLegFrq, string fixLegConv, string fltLegConv, 
            string fixLegDayCount, string fltLegDayCount, string holidays, bool endOfMonth = false)
        {
            Id = id;
            var market = Markets.Instance.GetMarket(marketName);
            var cache = Caches.Instance.GetCache(cacheName);
            var indx = market.GetIndex(index);
            var calendar = p.Calendar(holidays);
            var type = u.EnumParse<QLNet.VanillaSwap.Type>(p.PayRec(payRec));
		
		    var fixedSchedule = new Schedule(start, maturity, new Period(p.Freq(fixLegFrq)), calendar, p.BizConv(fixLegConv), p.BizConv(fixLegConv), DateGeneration.Rule.Forward, endOfMonth);
            var floatSchedule = new Schedule(start, maturity, new Period(p.Freq(fltLegFrq)), calendar, p.BizConv(fltLegConv), p.BizConv(fltLegConv), DateGeneration.Rule.Forward, endOfMonth);
            Underlying = new VanillaSwap(type, nominal, fixedSchedule, fixedRate, p.DayCount(fixLegDayCount), floatSchedule, indx, spread, p.DayCount((fltLegDayCount)));

            cache.Add(id, this, curveName);
        }
    }
}
